import requests
from bs4 import BeautifulSoup


def get_content(url, header):
    content = requests.get(url, headers = header).content
    return content
    
def get_html(content):
    html = content.decode("UTF-8")
    return html
    
def get_soup(html):
    soup = BeautifulSoup(html, "html.parser")
    return soup

# demo
def get_title(url, header):
    content = get_content(url, header)
    html = get_html(content)
    soup = get_soup(html)
    print(soup.title.text)

# 主体，爬取  热门视频排行榜的所有链接
def get_bilibili(url, header):
    content = get_content(url, header)
    html = get_html(content)
    soup = get_soup(html)
    rank_list = soup.findAll('li', {'class':'rank-item'})
    for rank in rank_list:
        title = rank.find(a, {'class':'title'}).text
        address = rank.find(a, {'class':'title'}).href


if __name__ == "__main__":
    url = "https://www.bilibili.com/ranking?spm_id_from=333.6.b_7072696d61727950616765546162.3"
    header = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}
    get_bilibili(url, header)
    
    
    
    
    
    
    